package io.renren.modules.waybillorder.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.waybillorder.entity.WaybillOrderEntity;
import io.renren.modules.waybillorder.service.WaybillOrderService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 运单
 *
 * @author cyx
 * @email 714529684@qq.com
 * @date 2022-02-22 21:25:47
 */
@RestController
@RequestMapping("generator/waybillorder")
public class WaybillOrderController {
    @Autowired
    private WaybillOrderService waybillOrderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:waybillorder:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = waybillOrderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{waybillno}")
    @RequiresPermissions("generator:waybillorder:info")
    public R info(@PathVariable("waybillno") Long id){
		WaybillOrderEntity waybillOrder = waybillOrderService.getById(id);

        return R.ok().put("waybillOrder", waybillOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:waybillorder:save")
    public R save(@RequestBody WaybillOrderEntity waybillOrder){
        waybillOrder.setCreateby(((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername());
        waybillOrder.setCreatetime(new Date());
		waybillOrderService.save(waybillOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:waybillorder:update")
    public R update(@RequestBody WaybillOrderEntity waybillOrder){
        waybillOrder.setUpdateby(((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername());
        waybillOrder.setUpdatetime(new Date());
		waybillOrderService.updateById(waybillOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:waybillorder:delete")
    public R delete(@RequestBody Long[] ids){
		waybillOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
